﻿using Microsoft.Extensions.DependencyInjection;
using System;
using TestServiceCollection.Implement;

namespace TestServiceCollection
{
    class Program
    {
        static void Main(string[] args)
        {
            var services = new ServiceCollection()
                .AddScoped<IOperationScoped, Operation>()
                .AddSingleton<IOperationSingleton, Operation>()
                .AddTransient<IOperationTransient, Operation>();

            var provider = services.BuildServiceProvider();
            using (var scope1 = provider.CreateScope())
            {
                var p = scope1.ServiceProvider;

                var scopeobj1 = p.GetService<IOperationScoped>();
                var transient1 = p.GetService<IOperationTransient>();
                var singleton1 = p.GetService<IOperationSingleton>();

                var scopeobj2 = p.GetService<IOperationScoped>();
                var transient2 = p.GetService<IOperationTransient>();
                var singleton2 = p.GetService<IOperationSingleton>();

                Console.WriteLine(
        $"scope1: { scopeobj1.OperationId },\r\n" +
        $"transient1: {transient1.OperationId},\r\n" +
        $"singleton1: {singleton1.OperationId}\r\n");

                Console.WriteLine($"scope2: { scopeobj2.OperationId }, \r\n" +
                    $"transient2: {transient2.OperationId}, \r\n" +
                    $"singleton2: {singleton2.OperationId}\r\n");
            }
        }
    }
}
